package com.go.where.manager.action.go;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;

import com.go.where.manager.action.SuperAction;
import com.go.where.manager.common.Constants;
import com.go.where.manager.freemarker.CustomFreemarkerManager;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.BigClassInfo;
import com.go.where.manager.pojo.OrderInfo;
import com.go.where.manager.pojo.SmallClassInfo;
import com.go.where.manager.pojo.user.OperatorInfo;
import com.go.where.manager.service.BigClassService;
import com.go.where.manager.service.OrderService;
import com.go.where.manager.service.SmallClassService;
import com.go.where.manager.service.system.OperatorService;

public class OrderAction extends SuperAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4383195694100314090L;
	private static final Logger log = Logger.getLogger(OrderAction.class);

	public Pagination<?> page;

	@Resource(name = "bigClassService")
	private BigClassService bigClassService;
	@Resource(name = "smallClassService")
	private SmallClassService smallClassService;
	@Resource(name = "orderService")
	private OrderService orderService;
	@Resource
	private OperatorService operatorService;

	private OrderInfo orderInfo;
	private OrderInfo orderInfoQuery;

	private List<BigClassInfo> bigClassList;
	private List<SmallClassInfo> smallClassList;

	private String orderId;
	private String auditResutlt;

	/**
	 * 查询列表
	 * 
	 * @return
	 */
	public String list() {
		if (orderInfoQuery == null) {
			orderInfoQuery = new OrderInfo();
			orderInfoQuery.setPageSize(Constants.INIT_PAGESIZE);
			orderInfoQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
		}
		try {
			orderInfoQuery.setIsDelete(Constants.NOT_DELETED);
			page = orderService.queryPage(orderInfoQuery);
		} catch (Exception e) {
			addActionError(e.getMessage());
			log.error("查询信息异常", e);
		}
		return LIST;
	}

	/**
	 * 详情
	 * 
	 * @return
	 */
	public String detail() {
		orderInfo = orderService.queryByPrimartKey(orderId);
		OperatorInfo op = operatorService
				.queryOperatorInfoByUserId(getCurrentOperator().getUserId());
		String mroleId = null;
		if (op != null) {
			String roleId = op.getRoleId();
			if (CustomFreemarkerManager.getValue("system.merchant.role.id")
					.equals(roleId)) {
				mroleId = roleId;
			}
		}
		BigClassInfo bi = new BigClassInfo();
		bi.setMroleId(mroleId);
		bigClassList = bigClassService.queryAll(bi);
		SmallClassInfo small = new SmallClassInfo();
		small.setClassId(orderInfo.getBigClassId());
		smallClassList = smallClassService.queryByBigClass(small);
		return "detail";
	}

	/**
	 * 假删除
	 * 
	 * @return
	 */
	public String falseDelete() {
		orderInfo = new OrderInfo();
		orderInfo.setOrderId(orderId);
		orderInfo.setIsDelete(Constants.DELETED);
		try {
			orderService.update(orderInfo, getCurrentOperator());
			redirectionUrl = "order!list.htm";
			return SUCCESS;
		} catch (Exception e) {
			log.error("删除信息异常", e);
			addActionError("删除信息异常" + e);
			return this.list();
		}
	}

	public String Auditing() {
		orderInfo = new OrderInfo();
		orderInfo.setOrderId(orderId);
		orderInfo.setOrderStatus(auditResutlt);
		try {
			orderService.update(orderInfo, getCurrentOperator());
			redirectionUrl = "order!list.htm";
			return SUCCESS;
		} catch (Exception e) {
			log.error("审核申请退款异常", e);
			addActionError("审核申请退款异常" + e);
			return this.list();
		}

	}

	public String getClassId() {
		return orderId;
	}

	public void setClassId(String classId) {
		this.orderId = classId;
	}

	public Pagination<?> getPage() {
		return page;
	}

	public void setPage(Pagination<?> page) {
		this.page = page;
	}

	public OrderInfo getOrderInfo() {
		return orderInfo;
	}

	public void setOrderInfo(OrderInfo orderInfo) {
		this.orderInfo = orderInfo;
	}

	public OrderInfo getOrderInfoQuery() {
		return orderInfoQuery;
	}

	public void setOrderInfoQuery(OrderInfo orderInfoQuery) {
		this.orderInfoQuery = orderInfoQuery;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public List<BigClassInfo> getBigClassList() {
		return bigClassList;
	}

	public void setBigClassList(List<BigClassInfo> bigClassList) {
		this.bigClassList = bigClassList;
	}

	public List<SmallClassInfo> getSmallClassList() {
		return smallClassList;
	}

	public void setSmallClassList(List<SmallClassInfo> smallClassList) {
		this.smallClassList = smallClassList;
	}

	public String getAuditResutlt() {
		return auditResutlt;
	}

	public void setAuditResutlt(String auditResutlt) {
		this.auditResutlt = auditResutlt;
	}

}
